<?php

namespace App\Models;

use App\Models\DeviceGroup;
use App\Models\SnsPic;
use App\Models\SnsVideo;
use App\Models\Device;
use Illuminate\Database\Eloquent\Model;

class Sns extends Model
{
  protected $hidden = array('pivot');

  public function deviceGroups()
  {
    return $this->belongsToMany(DeviceGroup::class);
  }

  public function snsPics()
  {
    return $this->hasMany(SnsPic::class);
  }

  public function snsVideo()
  {
    return $this->hasOne(SnsVideo::class);
  }

  public function postedDevices()
  {
    return $this->belongsToMany(Device::class, 'sns_device', 'sns_id', 'device_id');
  }

  public function hasPostedByDevice($device_id)
  {
    return $this->postedDevices->contains($device_id);
  }
}
